


	var app = new Vue({
	  el: '#app',
	  data: {
        controller: {
            isPhotoCon: false,
            alertText: false
        },
        navIndexAct:{
            ind:1,
            navTitle:[
                {
                    title:'基本资料填写',
                    isShowFu:true
                },
                {
                    title:'工作经历填写',
                    isShowFu:true
                },
                {
                    title:'评价填写',
                    isShowFu:true
                },
                {
                    title:'完成',
                    isShowFu:false
                }
            ]
        },
        basicsInformationId: 0,
        basicsInformation:{
            name:{
                type:'text',
                value: '',
                isAlert:false,
                name:'姓名',
                hintInfo:'请输入姓名'
            },
            phone:{
                type:'number',
                value: loginObj.getLogoinInfo(),
                isAlert:false,
                name:'手机号',
                hintInfo:'请输入正确的手机号'

            },
            id_card:{
                type:'text',
                value: '',
                isAlert:false,
                name:'身份证号',
                hintInfo:'请输入正确的身份证号'

            },
             province:{
                type:'select',
                value1: 1,
                value2: 1,
                isAlert:false,
                name:'籍贯',
                choosable1:[],
                choosable2:[],

            },
            PresentAddress:{
                type:'select',
                value1: 1,
                value2: '1',
                isAlert:false,
                name:'现住址',
                choosable1:[],
                choosable2:[],

            },
            nation_id:{
                type:'select',
                value1: 1,
                isAlert:false,
                name:'民族',
                hintInfo:'请输入民族',
                choosable1:[],

            },
            religion:{
                type:'select',
                value1: 1,
                isAlert:false,
                name:'宗教信仰',
                hintInfo:'请输入宗教信仰',
                choosable1:[],

            },
            height:{
                type:'number',
                value: '',
                isAlert:false,
                name:'身高',
                hintInfo:'请输入身高'

            },
            weight:{
                type:'number',
                value: '',
                isAlert:false,
                name:'体重',
                hintInfo:'请输入体重'

            },
            examination_date:{
                type:'date',
                value: '0000-00-00',
                isAlert:false,
                name:'体检日期',
                hintInfo:'请选择体检日期'

            },
            is_have_passport:{
                en:'Passport',
                type:'radio',
                value: '是',
                isAlert:false,
                name:'是否有护照',
                choosable:['是','否']
            },
            passport_due_date:{
                type:'date',
                value: '0000-00-00',
                isAlert:false,
                name:'护照到期时间',
                hintInfo:'请选择护照到期时间'

            },
            marital_status:{
                en:'marriage',
                type:'radio',
                value: '已婚',
                isAlert:true,
                name:'婚姻状况',
                choosable:['已婚','未婚','保密']

            },
            politics_status:{
                en:'political',
                type:'radio',
                value: '群众',
                isAlert:false,
                name:'政治面貌',
                choosable:['群众','党员','团员','民主党','其他']

            },

            blood_type:{
                en:'bloodType',
                type:'radio',
                value: '未知',
                isAlert:false,
                name:'血型',
                choosable:['未知','A','B','AB','O']

            },




        },


        workExperience: {
            isBjWork: {
                type:'radio',
                value: '是',
                isAlert:false,
                name:'是否有北京工作经验',
                choosable:['是','否'],
            },

            maternity:{
                value:'',
                value2:'',
                isAlert:false,
                name:'月嫂工作经验',
            },

            bringUp:{
                value:'',
                value2:'',
                isAlert:false,
                name:'育儿工作经验',
            },
            prematureWork: {
                type:'radio',
                value: '是',
                isAlert:false,
                name:'照顾早产儿经验',
                choosable:['是','否'],
            },
            TwinWork: {
                type:'radio',
                value: '是',
                isAlert:false,
                name:'照顾早产儿经验',
                choosable:['是','否'],
            },

        },
        workHistory: {
            HistoryList: [],
            temporaryData: {
                id:0,
                type: {
                    type:'radio',
                    value: '月嫂',
                    isAlert:false,
                    name:'类型',
                    choosable:['月嫂','育儿嫂'],
                },
                starttime: {
                    value: '',
                    isAlert:false,
                    name:'时间',
                },
                endtime: {
                    value: '',
                    isAlert:false,
                    name:'时间',
                },

                name: {
                    value: '',
                    isAlert:false,
                    name:'客户家庭',
                },
                babyage: {
                    value: '',
                    isAlert:false,
                    name:'宝宝育龄',
                },
                babydetail: {
                    value: '',
                    isAlert:false,
                    name:'宝宝情况',
                },
                money: {
                    value: '',
                    isAlert:false,
                    name:'到手工资',
                },
                PhotoList: []
            },
            initData: {
                id:0,
                type: {
                    type:'radio',
                    value: '月嫂',
                    isAlert:false,
                    name:'类型',
                    choosable:['月嫂','育儿嫂'],
                },
                starttime: {
                    value: '',
                    isAlert:false,
                    name:'时间',
                },
                endtime: {
                    value: '',
                    isAlert:false,
                    name:'时间',
                },
                name: {
                    value: '',
                    isAlert:false,
                    name:'客户家庭',
                },
                babyage: {
                    value: '',
                    isAlert:false,
                    name:'宝宝育龄',
                },
                babydetail: {
                    value: '',
                    isAlert:false,
                    name:'宝宝情况',
                },
                money: {
                    value: '',
                    isAlert:false,
                    name:'到手工资',
                },
                PhotoList: []
            }

        },
        customerEvaluation: {
            word:'',
            label: []
        },


	  },
       methods: {
        AddLabel: function(item) {
            this.customerEvaluation.word = this.customerEvaluation.word +'，'+ item;
        },

        AddPhotoList: function() {
            var url = $('#fileList').find('img.photo').attr('src');

            if (url) {
                this.workHistory.temporaryData.PhotoList.push({id:0, pic:url})
                this.controller.isPhotoCon = false;

            }else{
                this.AlertConFun('请添加照片')

            }
            $('#fileList').html(' ');


        },
        AddHistoryList: function() {

            for (var i in this.workHistory.temporaryData) {
                    if (this.workHistory.temporaryData[i].value == '' || this.workHistory.temporaryData[i].value2 == '') {
                        console.log('请填写' + this.workHistory.temporaryData[i].name)
                        this.AlertConFun('请填写' + this.workHistory.temporaryData[i].name)

                        return

                    }
                }

            this.workHistory.HistoryList.unshift(this.workHistory.temporaryData);
            this.workHistory.temporaryData = this.workHistory.initData;

        },
        deleteHistoryList: function(index, item) {
            if (item.id != 0) {
                console.log('请求删除 服务器 数据');


                axios.get(severUrl + 'delHistory?id='+item.id).then(function(response) {
                   if (response.data.success) {
                        app.workHistory.HistoryList.splice(index, 1);
                        app.AlertConFun('删除成功！')

                    }
                });

            }else{
             this.workHistory.HistoryList.splice(index, 1);
             this.AlertConFun('删除成功！')

            }
        },

        pageNext: function (event) {
          // this.navIndexAct.ind++;
            // console.log(this.navIndexAct.ind)

          if (this.navIndexAct.ind == 1) {


                for (var i in this.basicsInformation) {

                    this.dateChange(this.basicsInformation[i]);

                    if (this.basicsInformation[i].isAlert) {
                        console.log('请填写' +this.basicsInformation[i].name)
                        this.AlertConFun('请填写' +this.basicsInformation[i].name)
                        return
                    }
                }
                if (!this.identityVerification(this.basicsInformation.id_card.value)) {
                    this.basicsInformation.id_card.isAlert = true;
                    this.AlertConFun(this.basicsInformation.id_card.hintInfo);
                    return
                }


                this.navIndexAct.ind++;
          }else if (this.navIndexAct.ind == 2) {

            // for(var i in this.workExperience){
            //     // console.log(this.workExperience[i])


            // if (this.workExperience[i].value == '' || this.workExperience[i].value2 == '') {
            //         // console.log('请填写' +this.workExperience[i].name)
            //         this.AlertConFun('请填写' + this.workExperience[i].name)

            //         return
            //     }
            // }

            this.navIndexAct.ind++;
          }else if (this.navIndexAct.ind == 3) {
                if (this.customerEvaluation.word == '') {
                    this.AlertConFun('请填写客户评价')

                    return

                }
                this.submitDataInfo();

          }

        },

        //提交信息
        submitDataInfo:function(){
            var dataInfo = {
                Personal:{
                    code: GetQueryString('code'),
                    id: app.basicsInformationId,
                    name: app.basicsInformation.name.value,
                    phone: app.basicsInformation.phone.value,
                    id_card: app.basicsInformation.id_card.value,
                    native_province: app.basicsInformation.province.value1,
                    native_city: app.basicsInformation.province.value2,
                    current_live_province: app.basicsInformation.PresentAddress.value1,
                    current_live_city: app.basicsInformation.PresentAddress.value2,
                    nation_id: app.basicsInformation.nation_id.value1,
                    religion: app.basicsInformation.religion.value1,
                    height: app.basicsInformation.height.value,
                    weight: app.basicsInformation.weight.value,
                    examination_date: app.basicsInformation.examination_date.value,
                    is_have_passport: app.basicsInformation.is_have_passport.value,
                    passport_due_date: app.basicsInformation.passport_due_date.value,
                    marital_status: app.basicsInformation.marital_status.value,
                    politics_status: app.basicsInformation.politics_status.value,
                    blood_type: app.basicsInformation.blood_type.value,
                    is_have_bj_experience: app.workExperience.isBjWork.value,
                    maternity_matron_experience: app.workExperience.maternity.value,
                    m_m_look_children: app.workExperience.maternity.value2,
                    infants_nurse_experience: app.workExperience.bringUp.value,
                    i_n_look_children: app.workExperience.bringUp.value2,
                    is_have_premature_experience: app.workExperience.prematureWork.value,
                    is_have_twins_experience: app.workExperience.TwinWork.value,
                    customer_evaluation: app.customerEvaluation.word,
										userid: window.localStorage.userid
                },


                HistoryList: app.workHistory.HistoryList

            }

            axios({
              method: 'post',
              url: severUrl + 'addHouseworker',
              data: dataInfo,
            })
            .then(function(response) {
                if (response.data.success) {
                    app.navIndexAct.ind ++ ;
                }

            });
        },
        dateChange: function (val) {
            // console.log(val.value);

            if (val.value == '') {
                val.isAlert = true;
                // console.log(val);
            }else{
               val.isAlert = false;
                // console.log(val);
            }

        },
        AlertConFun: function(string) {
            this.controller.alertText = string;

            setTimeout(function(argument) {
                this.app._data.controller.alertText = false;
            },1500)

        },

        GetCityList: function(val, oldval){
            // console.log(val);
            this.AjaxCityList(val, app.basicsInformation.province)


        },
        GetCityListTwo: function(val, oldval){
            // console.log(val);
            this.AjaxCityList(val, app.basicsInformation.PresentAddress)


        },
        AjaxCityList: function(val, obj){
            axios.get(severUrl + 'getArea?id=' +val).then(function(response) {
                obj.value2 =  response.data[0].id;
                obj.choosable2 =  response.data;

            });

        },
        identityVerification: function(id) {
            var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
           if(reg.test(id)){
               return  true
           }else{
               return false
           }
        }
      },
       watch: {
        'basicsInformation.name': {
              handler: 'dateChange',
              deep: true
        },
        'basicsInformation.phone': {
              handler: 'dateChange',
              deep: true
        },
        'basicsInformation.id_card': {
              handler: function(val){
                if(this.identityVerification(val.value)){
                       val.isAlert = false
                   }else{
                       val.isAlert = true
                   }
              },
              deep: true
        },

        'basicsInformation.religion': {
              handler: 'dateChange',
              deep: true
        },
        'basicsInformation.height': {
              handler: 'dateChange',
              deep: true
        },
        'basicsInformation.weight': {
              handler: 'dateChange',
              deep: true
        },

        'basicsInformation.province.value1': 'GetCityList',
        'basicsInformation.PresentAddress.value1': 'GetCityListTwo',

       },
       created: function (){
            // console.log('加载')


            var phone = loginObj.getLogoinInfo() || 0;
            // var phone = 15;

            axios.get(severUrl+'getHouseworker?phone=' + phone).then(function(response) {
                var data = response.data;
                //如果之前填写过信息
                if (data.isEmpty) {

                    if (data.Personal) {

                        //个人资料

                        app.basicsInformationId = data.Personal.id;

                        app.basicsInformation.name.value = data.Personal.name;

                        app.basicsInformation.id_card.value = data.Personal.id_card;

                        app.basicsInformation.province.value1 = data.Personal.native_province;

                        app.basicsInformation.province.value2 = data.Personal.native_city;

                        app.basicsInformation.PresentAddress.value1 = data.Personal.current_live_province;

                        app.basicsInformation.PresentAddress.value2 = data.Personal.current_live_city;

                        app.basicsInformation.nation_id.value1 = data.Personal.nation_id;

                        app.basicsInformation.religion.value1 = data.Personal.religion;

                        app.basicsInformation.height.value = data.Personal.height;

                        app.basicsInformation.weight.value = data.Personal.weight;

                        app.basicsInformation.examination_date.value = data.Personal.examination_date;

                        app.basicsInformation.is_have_passport.value = data.Personal.is_have_passport;

                        app.basicsInformation.passport_due_date.value = data.Personal.passport_due_date;

                        app.basicsInformation.marital_status.value = data.Personal.marital_status;

                        app.basicsInformation.politics_status.value = data.Personal.politics_status;

                        app.basicsInformation.blood_type.value = data.Personal.blood_type;



                        //工作经验
                        app.workExperience.isBjWork.value = data.Personal.is_have_bj_experience;

                        app.workExperience.maternity.value = data.Personal.maternity_matron_experience;

                        app.workExperience.maternity.value2 = data.Personal.m_m_look_children;

                        app.workExperience.bringUp.value = data.Personal.infants_nurse_experience;

                        app.workExperience.bringUp.value2 = data.Personal.i_n_look_children;

                        app.workExperience.prematureWork.value = data.Personal.is_have_premature_experience;

                        app.workExperience.TwinWork.value = data.Personal.is_have_twins_experience;

                        //自我评价
                        app.customerEvaluation.word = data.Personal.customer_evaluation;






                    }


                    //工作 经历
                    if (data.HistoryList) {

                        app.workHistory.HistoryList = data.HistoryList;

                    }


                }
                // 地区列表
                if (data.AreaList) {
                    app.basicsInformation.province.choosable1 = data.AreaList;
                    app.basicsInformation.PresentAddress.choosable1 = data.AreaList;
                }
                // 民族列表
                if (data.NationList) {
                    app.basicsInformation.nation_id.choosable1 = data.NationList;

                }
                //宗教信仰
                if (data.ReligionList) {
                    app.basicsInformation.religion.choosable1 = data.ReligionList;

                }
                // 自我评价标签
                if (data.EvaluationList) {
                    app.customerEvaluation.label = data.EvaluationList;
                }

            });





        }


	})
